package util;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
import java.util.Locale;

import static java.lang.System.*;

/**
 * Created by IntelliJ IDEA.
 * User: Altair
 * Date: 17.03.12
 * Time: 23:06
 * To change this template use File | Settings | File Templates.
 * класс осуществляет подключение к базе
 * вынес отдельно потому что возникали накладки с работто lisnera
 */
public class conectionDB {
    final private static String driverName = "oracle.jdbc.driver.OracleDriver";
    private static String url;
    final private static String server = "localhost";
    final private static String port = "1521";
    final private static String sid = "xe";
    final private static String username = "test";
    final private static String password = "123456";

    /**
     *
     * @return
     * @throws ClassNotFoundException
     */
    public Connection conect() throws ClassNotFoundException {
        boolean  flag = false;
        java.sql.Connection con = null;
        try{      url = "jdbc:oracle:thin:@" + server
                + ":" + port + ":" + sid;
           // System.out.println(url);

            Class.forName(driverName);
            Locale.setDefault(Locale.ENGLISH);
             con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe",
                    username, password);
           // out.println("connecting: " + url);
            if(!con.equals(null)){
                /*
                out.println("The connection is successfully established. Server: "
                + server + ":" + port + ":" + sid + "/n");
                */

                flag = true;
            }
        }   catch (SQLException ex) {
            ex.printStackTrace();
            flag = false;

        }
     return con;
    }
}
